package com.pattern.observer;

import java.util.ArrayList;
import java.util.List;
/**
 * 观察者模式：目标对象
 * 管理观察者列表，
 * 发布消息通知给观察者
 * @author liuxiaodong
 * @date 2017-1-16 14:34
 */
public class SubjectImpl implements Subject {
	private String message;

	private List<Observer> observers = new ArrayList<Observer>();

	@Override
	public void attach(Observer observer) {
		observers.add(observer);
	}

	@Override
	public void dettach(Observer observer) {
		observers.remove(observer);
	}

	@Override
	public void notifyObservers() {
		for(Observer obj : observers){
			obj.update(this);
		}
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
}
